package com.transitionseverywhere;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Path;
import android.util.AttributeSet;

/* loaded from: classes.dex */
public class ArcMotion extends PathMotion {
    private static final float DEFAULT_MAX_ANGLE_DEGREES = 70.0f;
    private static final float DEFAULT_MAX_TANGENT = (float) Math.tan(Math.toRadians(35.0d));
    private static final float DEFAULT_MIN_ANGLE_DEGREES = 0.0f;
    private float mMaximumAngle;
    private float mMaximumTangent;
    private float mMinimumHorizontalAngle;
    private float mMinimumHorizontalTangent;
    private float mMinimumVerticalAngle;
    private float mMinimumVerticalTangent;

    public ArcMotion() {
        this.mMinimumHorizontalAngle = 0.0f;
        this.mMinimumVerticalAngle = 0.0f;
        this.mMaximumAngle = DEFAULT_MAX_ANGLE_DEGREES;
        this.mMinimumHorizontalTangent = 0.0f;
        this.mMinimumVerticalTangent = 0.0f;
        this.mMaximumTangent = DEFAULT_MAX_TANGENT;
    }

    public ArcMotion(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mMinimumHorizontalAngle = 0.0f;
        this.mMinimumVerticalAngle = 0.0f;
        this.mMaximumAngle = DEFAULT_MAX_ANGLE_DEGREES;
        this.mMinimumHorizontalTangent = 0.0f;
        this.mMinimumVerticalTangent = 0.0f;
        this.mMaximumTangent = DEFAULT_MAX_TANGENT;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.ArcMotion);
        setMinimumVerticalAngle(obtainStyledAttributes.getFloat(R.styleable.ArcMotion_minimumVerticalAngle, 0.0f));
        setMinimumHorizontalAngle(obtainStyledAttributes.getFloat(R.styleable.ArcMotion_minimumHorizontalAngle, 0.0f));
        setMaximumAngle(obtainStyledAttributes.getFloat(R.styleable.ArcMotion_maximumAngle, DEFAULT_MAX_ANGLE_DEGREES));
        obtainStyledAttributes.recycle();
    }

    public void setMinimumHorizontalAngle(float f) {
        this.mMinimumHorizontalAngle = f;
        this.mMinimumHorizontalTangent = toTangent(f);
    }

    public float getMinimumHorizontalAngle() {
        return this.mMinimumHorizontalAngle;
    }

    public void setMinimumVerticalAngle(float f) {
        this.mMinimumVerticalAngle = f;
        this.mMinimumVerticalTangent = toTangent(f);
    }

    public float getMinimumVerticalAngle() {
        return this.mMinimumVerticalAngle;
    }

    public void setMaximumAngle(float f) {
        this.mMaximumAngle = f;
        this.mMaximumTangent = toTangent(f);
    }

    public float getMaximumAngle() {
        return this.mMaximumAngle;
    }

    private static float toTangent(float f) {
        if (f < 0.0f || f > 90.0f) {
            throw new IllegalArgumentException("Arc must be between 0 and 90 degrees");
        }
        return (float) Math.tan(Math.toRadians(f / 2.0f));
    }

    @Override // com.transitionseverywhere.PathMotion
    public Path getPath(float f, float f2, float f3, float f4) {
        float f5;
        float f6;
        float f7;
        Path path = new Path();
        path.moveTo(f, f2);
        if (f2 == f4) {
            f5 = (f + f3) / 2.0f;
            f6 = ((this.mMinimumHorizontalTangent * Math.abs(f3 - f)) / 2.0f) + f2;
        } else if (f == f3) {
            f5 = ((this.mMinimumVerticalTangent * Math.abs(f4 - f2)) / 2.0f) + f;
            f6 = (f2 + f4) / 2.0f;
        } else {
            float f8 = f3 - f;
            float f9 = f4 - f2;
            float f10 = (f8 * f8) + (f9 * f9);
            float f11 = (f + f3) / 2.0f;
            float f12 = (f2 + f4) / 2.0f;
            float f13 = 0.25f * f10;
            boolean z = f8 * f9 > 0.0f;
            if (Math.abs(f8) < Math.abs(f9)) {
                float f14 = f10 / (f9 * 2.0f);
                if (z) {
                    f6 = f2 + f14;
                    f5 = f;
                } else {
                    f6 = f4 - f14;
                    f5 = f3;
                }
                f7 = this.mMinimumVerticalTangent;
            } else {
                float f15 = f10 / (f8 * 2.0f);
                if (z) {
                    f5 = f3 - f15;
                    f6 = f4;
                } else {
                    f5 = f + f15;
                    f6 = f2;
                }
                f7 = this.mMinimumHorizontalTangent;
            }
            float f16 = f13 * f7 * f7;
            float f17 = f11 - f5;
            float f18 = f12 - f6;
            float f19 = (f17 * f17) + (f18 * f18);
            float f20 = this.mMaximumTangent;
            float f21 = f13 * f20 * f20;
            if (f19 >= f16) {
                f16 = f19 > f21 ? f21 : 0.0f;
            }
            if (f16 != 0.0f) {
                float sqrt = (float) Math.sqrt(f16 / f19);
                f5 = ((f5 - f11) * sqrt) + f11;
                f6 = f12 + (sqrt * (f6 - f12));
            }
        }
        path.cubicTo((f + f5) / 2.0f, (f2 + f6) / 2.0f, (f5 + f3) / 2.0f, (f6 + f4) / 2.0f, f3, f4);
        return path;
    }
}
